package com.wangjie.simple;

import java.util.Arrays;

/**
 * @author jieshao
 * @date 2022/5/30 14:51
 *
 * 1984. 学生分数的最小差值
 */
public class Test11 {
    public static void main(String[] args) {
        int[] arr = {9, 4, 1, 7};
        int res = minimumDifference(arr, 2);
        System.out.println(res);
    }

    public static int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i + k - 1 < nums.length; i++) {
            min = Math.min(min, nums[i + k - 1] - nums[i]);
        }
        return min;
    }
}